#include "Player.h"

Player::Player(void) : Character()
{
}

Player::Player(Socket* _socket, int _entity_index, int _x, int _y, int _h) : Character(_entity_index, _x, _y, _h) {
	socket = _socket;
	in_buffer = new Buffer(5000);
	out_buffer = new Buffer(5000);
}

int Player::get_data(int amount) {
	in_buffer->data = in_buffer->start;
	
	int i = socket->receive(in_buffer->data, amount);
	if(i != amount)
		disconnect = true;
	return i;
}

int Player::flush_data() {
	int i = socket->send(out_buffer->start, out_buffer->data - out_buffer->start);
	if(i != out_buffer->data - out_buffer->start)
		disconnect = false;
	out_buffer->data = out_buffer->start;
	return i;
}

Player::~Player(void)
{
	delete[] username;
	delete[] password;
	delete in_buffer;
	delete out_buffer;
}
